package com.wfs.suanfa.nio.xiaoliu;

import java.io.*;
import java.net.Socket;

/**
 * @author wfs
 * @date 2021/3/28 21:32
 */
public class TCPClient {
    public static void main(String[] args) {
        try {
            Socket s=new Socket("127.0.0.1",6666);
            OutputStream os = s.getOutputStream();
            //发送
            DataOutputStream dos = new DataOutputStream(os);
            dos.writeUTF("Hello server!");
            //接受
            DataInputStream dis = new DataInputStream(s.getInputStream());
            System.err.println(dis.readUTF());
            dos.flush();
            dos.close();
            dis.close();
            s.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
